<?php
class ModelLanguage
{
	public function construct()
	{
		
	}
	
	public function getLanguageText()
	{
		DB::exec("SET NAMES 'utf8'");
		$sql = "SELECT id, en_text, sin_text, tamil_text, section
				FROM tbl_labels";		
		$rs = DB::fetchAll($sql);
		
		return $rs;
	}
	
	public function getLanguageTextById($id)
	{
		DB::exec("SET NAMES 'utf8'");
		$sql = "SELECT en_text, sin_text, tamil_text, section
				FROM tbl_labels
				WHERE id = " . $id;		
		$rs = DB::fetchRow($sql);
		
		return $rs;
	}
	
	public function updateLanguage($formval)
	{
		DB::exec("SET NAMES 'utf8'");
		$language_id = $formval['language_id'];
		$lang = $formval['lang'];
		$label = $formval['label'];
		
		if($lang == "en")
		{
			$field = "en_text";
		} else if($lang == "sin") {
			$field = "sin_text";
		} else if($lang == "tamil") {
			$field = "tamil_text";		
		}
		
		$sql = "UPDATE tbl_labels
				SET " . $field . " = '" . $label . "' 
				WHERE id = " . $language_id;
		$update_label = DB::exec($sql);
		
		if($update_label)
		{
			echo "<span class='success'>Selected label has been updated</span>";
		}
		
	}
}
?>